package com.wm.mvp.base

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import butterknife.ButterKnife
import com.blankj.utilcode.util.BusUtils
import com.wm.mvp.BaseModel
import com.wm.mvp.BaseMvp
import com.wm.mvp.BasePresenter
import com.wm.mvp.BaseView

abstract class BaseActivity<M:BaseModel,V:BaseView,P:BasePresenter<M,V>>:AppCompatActivity(),BaseMvp<M,V,P> {

    var presenter:P? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(getLayoutId())
        BusUtils.register(this)
        ButterKnife.bind(this)
        presenter = createPresenter()
        presenter?.registerModel(createMode())
        presenter?.registerView(createView())
        initView()
        initData()
    }

    abstract fun getLayoutId():Int

    /**
     * 初始化控件
     */
    abstract fun initView()

    /**
     * 初始化数据
     */
    abstract fun initData()


    override fun onDestroy() {
        super.onDestroy()
        BusUtils.unregister(this)
    }

}